package com.wjc.train.member.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wjc.train.common.context.LoginMemberContext;
import com.wjc.train.common.resp.CommonResp;
import com.wjc.train.common.untils.PageUtil;
import com.wjc.train.member.req.TicketQueryReq;
import com.wjc.train.member.req.TicketSaveReq;
import com.wjc.train.member.resp.TicketQueryResp;
import com.wjc.train.member.service.ITicketService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 会员车票 前端控制器
 * </p>
 *
 * @author Guessed
 * @since 2023-08-22
 */
@RestController
@Validated
@RequestMapping("/ticket")
public class TicketController {

    @Resource
    private ITicketService ticketService;

    @PostMapping("/save")
    public CommonResp save(@RequestBody @Valid TicketSaveReq ticketSaveReq){
        ticketService.save(ticketSaveReq);
        return CommonResp.success();
    }

    @PostMapping("/query-list")
    public CommonResp queryList(@RequestBody TicketQueryReq ticketQueryReq){
        IPage<TicketQueryResp> iPage =
        ticketService.queryList(PageUtil.getPage(ticketQueryReq.getQueryPage()), ticketQueryReq);
        return CommonResp.success(new PageUtil(iPage));
    }

    @DeleteMapping ("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        ticketService.delete(id);
        return CommonResp.success();
    }
    @PostMapping("/query-listForMember")
    public CommonResp queryListForMember(@RequestBody TicketQueryReq ticketQueryReq){
        ticketQueryReq.setMemberId(LoginMemberContext.getId());
        IPage<TicketQueryResp> iPage =
                ticketService.queryList(PageUtil.getPage(ticketQueryReq.getQueryPage()), ticketQueryReq);
        return CommonResp.success(new PageUtil(iPage));
    }

}


